﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class HUDVday2011Component extends HUDComponent implements IPlayerStateObserver {

        private var m_icon:AutoAnimatedBitmap = null;
        private var m_iconHolder:AssetPane;
        private var m_heartText:JTextField;
        private var m_locked:Boolean = false;
        private var m_created:Boolean = false;

        public function HUDVday2011Component(){
            Global.player.addObserver(this);
            if (Global.player.level < 5){
                this.m_locked = true;
            };
            if (((!(this.m_locked)) && (!(this.m_created)))){
                this.create();
                this.m_created = true;
            };
        }
        private function create():void{
            m_jWindow = new JWindow(this);
            m_jPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, 0xFFFFFF, true);
            _local1.align = TextFormatAlign.RIGHT;
            this.addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
            m_jPanel.append(ASwingHelper.verticalStrut(15));
            this.m_heartText = ASwingHelper.makeTextField(ValentineManager.getTotalAdmirers().toString(), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 16, 0xFFFFFF, 0, _local1);
            LoadingManager.load(Global.getAssetURL("assets/hud/heart2_71x66.png"), this.onIconLoaded);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local2.append(ASwingHelper.horizontalStrut(0));
            _local2.append(this.m_heartText, BorderLayout.CENTER);
            m_jPanel.append(_local2);
            m_jWindow.setContentPane(m_jPanel);
            ASwingHelper.prepare(m_jWindow);
            m_jWindow.cacheAsBitmap = true;
            m_jWindow.show();
            this.alpha = 0;
            this.visible = false;
            if (!this.m_locked){
                this.visible = true;
                Z_TweenLite.to(this, 1, {alpha:1});
                this.addTooltip();
                this.addCounter();
            };
        }
        private function onIconLoaded(_arg1:Event):void{
            var _local3:Bitmap;
            var _local2:Loader = (_arg1.target.loader as Loader);
            if ((_local2.content is Bitmap)){
                _local3 = (_local2.content as Bitmap);
                this.m_icon = new AutoAnimatedBitmap(_local3.bitmapData, 30, 71, 66, 30);
                this.m_icon.x = 0;
                this.m_icon.y = 0;
                if (ValentineManager.getNewValentines().length){
                    this.m_icon.play();
                } else {
                    this.m_icon.stop();
                };
                addChildAt(this.m_icon, 0);
                m_jPanel.setPreferredSize(new IntDimension(this.m_icon.width, this.m_icon.height));
                m_jPanel.setMinimumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
                m_jPanel.setMaximumSize(new IntDimension(this.m_icon.width, this.m_icon.height));
                ASwingHelper.prepare(m_jWindow);
            };
        }
        private function onMouseClick(_arg1:Event):void{
            if (!this.m_locked){
                StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.HUD, "icon_click");
                UI.displayValentineDialog();
                this.m_icon.currentFrame = 0;
                this.m_icon.updateMe(null);
                this.m_icon.stop();
            };
        }
        private function addTooltip():void{
            m_toolTip = new ToolTip(function ():String{
                return (ZLoc.t("Dialogs", "ValUI_HUD_tooltip"));
            });
            m_toolTip.attachToolTip(m_jPanel);
            m_toolTip.hideCursor = true;
        }
        private function addCounter():void{
            this.m_heartText.setText(ValentineManager.getTotalAdmirers().toString());
        }
        override public function updateCounter(... _args):void{
            this.m_heartText.setText(ValentineManager.getTotalAdmirers().toString());
        }
        public function levelChanged(_arg1:int):void{
            var _local2:GenericPictureDialog;
            if (_arg1 == 5){
                this.m_locked = false;
                if (this.m_created == false){
                    this.create();
                    this.m_created = true;
                };
                this.visible = true;
                Z_TweenLite.to(this, 1, {alpha:1});
                this.addTooltip();
                this.addCounter();
                if (!Global.player.getSeenFlag("vday_newbie")){
                    _local2 = new GenericPictureDialog(ZLoc.t("Announcements", "Announcement09_text"), "", GenericDialogView.TYPE_OK, null, ZLoc.t("Announcements", "Announcement09_title"), "", true, 0, "Okay", "assets/announcements/valentines_announceimage_452x352.png");
                    UI.displayPopup(_local2);
                    Global.player.setSeenFlag("vday_newbie");
                };
            };
        }
        public function xpChanged(_arg1:int):void{
        }
        public function commodityChanged(_arg1:int, _arg2:String):void{
        }
        public function energyChanged(_arg1:Number):void{
        }
        public function goldChanged(_arg1:int):void{
        }
        public function cashChanged(_arg1:int):void{
        }

    }
}//package Display.hud.components 
